<template>
	<cl-crud @load="onLoad"></cl-crud>
</template>

<script>
export default {
	name: 'account',
	data() {
		return {
			crud: null,
			selectRow: [], // 当前选中行
			accountList: []
		};
	},
	methods: {
		onLoad({ ctx, app }) {
			this.crud = app;

			ctx.service(this.$service.promotion.account)
				.set('table', {
					columns: [
						{
							label: '序号',
							type: 'index',
							align: 'center'
						},
						{
							label: '所属联盟',
							prop: 'account',
							align: 'center'
						},
						{
							label: 'PID备注',
							prop: 'remark',
							align: 'center'
						},
						{
							label: '推广位PID',
							prop: 'pid',
							align: 'center'
						},
						{
							label: 'PID状态',
							prop: 'status',
							align: 'center',
							dict: [
								{
									label: '正常',
									value: 1
								},
								{
									label: '停用',
									value: 0
								}
							]
						}
					]
				})
				.set('upsert', {
					props: {
						width: '700px',
						labelWidth: '150px'
					},
					items: [
						{
							prop: 'taobaoId',
							label: '所属联盟：',
							span: 12,
							component: {
								name: 'el-select',
								options: [],
								props: {
									clearable: true,
									filterable: true
								},
								attrs: {
									placeholder: '请选择所属联盟'
								}
							},
							rules: {
								required: true,
								message: '所属联盟不能为空'
							}
						},
						{
							prop: 'pid',
							label: 'PID：',
							component: {
								name: 'el-input',
								attrs: {
									placeholder: 'PID必须是授权账号下的PID',
									clearable: true
								}
							},
							rules: {
								required: true,
								message: 'PID必须不能为空'
							}
						},
						{
							prop: 'remark',
							label: 'PID备注：',
							component: {
								name: 'el-input',
								attrs: {
									placeholder: '1-10个字，方便识别使用不同的pid',
									clearable: true
								}
							},
							rules: {
								required: true,
								message: 'PID备注不能为空'
							}
						}
					]
				})
				.set('layout', [
					['refresh-btn', 'add-btn', 'slot-filter', 'flex1', 'search-key'],
					['data-table'],
					['flex1', 'pagination']
				])
				.on('open', () => {
					this.$service.account.union.list().then(res => {
						this.accountList = res;

						let arr = [];
						this.accountList.forEach(item => {
							arr.push({
								label: item.account,
								value: item.id
							});
						});
						app.setData('upsert.items[prop:taobaoId].component.options', arr);
					});
				})
				.done();
			app.refresh(this.params);
		}
	}
};
</script>

<style scoped></style>
